package com.acme.bankapp.service.bank;
/**
 * TODO: Please add file description for  @fileCheckingAccount.java
 * Created: Nov 8, 2013 5:39:03 PM
 */

/**
 * @author Andrey Alekov
 * Checking account.
 */
public class CheckingAccount extends AbstractAccount {
	private double overdraft;
	
	public CheckingAccount(double amount) {
		super(amount);
	}
	
	public CheckingAccount(double amount, double overdraft) {
		super(amount);
		this.overdraft = overdraft;
	}
	
	public double getOverdraft() {
		return overdraft;
	}

	public void setOverdraft(double overdraft) {
		this.overdraft = overdraft;
	}

	/* (non-Javadoc)
	 * @see com.acme.bankapp.service.bank.AbstractAccount#maximumAmounToWithdraw()
	 * Return allowed balance with overdraft.
	 */
	@Override
	public double maximumAmountToWithdraw() {
		return (balance + overdraft);
	}

	@Override
	public boolean deposit(double amount) {
		this.balance = this.balance + amount;
		// TODO: Limits of account to deposit. Need to clarify from client.
		return true;
	}
	@Override
	public boolean withdraw(double amount) {
		// FIXME: Rewrite to using assertions.
		if ((this.balance + this.overdraft) >= amount){
			if (this.balance > amount){
				this.balance -= amount;
				return true;
			}
			if (this.balance == 0d){
				this.overdraft -= amount;
			}
			else{
				double overdrafted = this.balance - amount;
				this.balance = 0d;
				this.overdraft -= overdrafted;
			}
			return true;
		}
		else{
			return false;
		}
	}
}